<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head> 
<title>${type=='save'?'添加':'修改' }管理员</title>
<%@ include file="../../../common/base.jsp" %>
</head>

<body id="body">
<!--head-->
<div id="head">
	<%@ include file="../../../common/head.jsp" %>
</div>
<!--head end-->
<!--container-->
<div id="container">
	<div id="pageId" style="display: none;">04-02-01</div>
		<!--sidebar-->
		<%@ include file="../../../common/menu.jsp" %>
	    <!--sidebar-->
    <!--main-->
    <div class="main">
    	<div class="location" style="background-position:22px -109px;">
        	系统管理<span>&gt;</span>操作员管理<span>&gt;</span>${sutype=='save'?'添加':'修改' }管理员
        </div>
        <!--content-->
        <div class="content">
        	<input type="hidden" id="operatorId" value="${ossOperator.OPERATOR_ID }">
        	<h2 class="tit_blue">${sutype=='save'?'添加':'修改' }管理员(带<span class="red">*</span>号为必填字段)</h2>
            <div class="inputInfoList3">
                <ul>
                    <li>
                    	<c:if test="${sutype=='save'}">
                    		<label>登录名</label><input type="text" onFocus="this.style.border = '1px solid #2A7CCF'"  class="text" id="loginName" value="${ossOperator.LOGIN_NAME }" onBlur="loginNameValide(this);this.style.border = '1px solid #D5D5D5'">
                    		<span class='red'>*</span>
                    	</c:if>
                    	<c:if test="${sutype=='update'}">
	                        <label>登录名</label><input type="text" onFocus="this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'" readonly="readonly" class="text" id="loginName" value="${ossOperator.LOGIN_NAME }">
                    	</c:if>
                    </li>
                	<c:if test="${sutype=='save'}">
	                    <li>
	                        <label>登录密码</label><input type="password" class="text" id="loginPwd" onFocus="this.style.border = '1px solid #2A7CCF'" onBlur="loginPwdValide(this);this.style.border = '1px solid #D5D5D5'">
	                        <span class='red'>*</span>
	                    </li>
	                    <li>
	                        <label>确认登录密码</label><input type="password" class="text" id="confirmPwd" onFocus="this.style.border = '1px solid #2A7CCF'" onBlur="confirmPwdValide(this);this.style.border = '1px solid #D5D5D5'">
	                        <span class='red'>*</span>
	                    </li>
                	</c:if>
                    <li>
                   		<label>用户姓名</label><input type="text" onFocus="this.style.border = '1px solid #2A7CCF'"  class="text" id="name" value="${ossOperator.NAME }" onBlur="userNameValide(this);this.style.border = '1px solid #D5D5D5'">
                   		<span class='red'>*</span>
                    </li>
					<li>
						<label>联系电话</label><input type="text" onFocus="this.style.border = '1px solid #2A7CCF'"  class="text" id="phone" value="${ossOperator.PHONE }" onBlur="phoneValide(this);this.style.border = '1px solid #D5D5D5'">
						<span class='red'>*</span>
					</li>



                    <%--
                    <li>
                        <label>所属公司</label><input type="text" onFocus="this.style.border = '1px solid #2A7CCF'"  class="text" id="company" value="${ossOperator.COMPANY }" onBlur="companyValide(this);this.style.border = '1px solid #D5D5D5'">
                        <span class='red'>*</span>
                    </li>
                    <li>
                        <label>所属部门</label>
                        <select id="department">
                            <c:forEach var="department" items="${departmentList }">
	                        	<c:choose>
								   <c:when test="${ossOperator.DEPARTMENT==department.enumCode}">
								   		<option data-val="${department.enumName }" value="${department.enumCode }" selected="selected">${department.enumName }</option>
								   </c:when>
								   <c:otherwise>
								   		<option data-val="${department.enumName }" value="${department.enumCode }">${department.enumName }</option>
								   </c:otherwise>
								</c:choose>
	                        </c:forEach>
                        </select>
                    </li>
                    <li>
                        <label>职称</label>
                        <select id="position">
                            <c:forEach var="position" items="${positionList }">
	                        	<c:choose>
								   <c:when test="${ossOperator.POSITION==position.enumCode}">
								   		<option data-val="${position.enumName }" value="${position.enumCode }" selected="selected">${position.enumName }</option>
								   </c:when>
								   <c:otherwise>
								   		<option data-val="${position.enumName }" value="${position.enumCode }">${position.enumName }</option>
								   </c:otherwise>
								</c:choose>
	                        </c:forEach>
                        </select>
                    </li>--%>

                    <li>
                        <label>分配角色</label>
                        <select id="roleId" <c:if test="${ossOperator.OPERATOR_ID ==10000 }"> disabled="disabled"</c:if>>                        	
	                        <c:forEach var="ossRole" items="${ossRoleList }">
	                        	<c:choose>
								   <c:when test="${ossOperator.ROLE_ID==ossRole.roleId}">
								   		<option data-val="${ossRole.roleName }" value="${ossRole.roleId }" selected="selected">${ossRole.roleName }</option>
								   </c:when>
								   <c:otherwise>
								   		<option data-val="${ossRole.roleName }" value="${ossRole.roleId }">${ossRole.roleName }</option>
								   </c:otherwise>
								</c:choose>
	                        </c:forEach>
	                        <c:if test="${ossOperator.OPERATOR_ID ==10000 }">
                        		<option value="admin" selected="selected">admin</option>
                        	</c:if>
						</select>
                    </li>
                    <li>
                        <label>用户类型</label>
                        <input type="hidden" id="type" name="type">
                        <c:if test="${sutype=='save'}">
	                        <span class="power">
	                            <em><input type="radio" name="chType" value="0" onchange="changeType();" checked/>平台系统用户</em>
	                            <em><input type="radio" name="chType" value="1" onchange="changeType();" />合作商系统用户</em>
	                        </span>
	                    </c:if>
	                     <c:if test="${sutype=='update'}">
	                        <span class="power">
	                            <em><input type="radio" name="chType" value="0" onchange="changeType();" <c:if test="${ossOperator.TYPE==0}">checked="checked"</c:if> />平台系统用户</em>
	                            <em><input type="radio" name="chType" value="1" onchange="changeType();" <c:if test="${ossOperator.TYPE==1}">checked="checked"</c:if> />合作商系统用户</em>
	                        </span>
	                    </c:if>
                    </li>
					<c:if test="${sutype=='save'}">
						<li id="partnerIdLi" style="display: none;">
					</c:if>
					<c:if test="${sutype=='update'}">
					<li id="partnerIdLi" <c:if test="${ossOperator.TYPE==0}">style="display: none;"</c:if>>
					</c:if>
						<label>用户所属合作商(维修中心)</label>
						<select id="partnerId" name = "partnerId">
							<option value="0" >---请选择用户所属合作商---</option>
							<c:forEach var="rl" items="${repairList }">
								<c:choose>
									<c:when test="${ossOperator.PARTNER_ID==rl.id}">
										<option data-val="${rl.repairName }" value="${rl.id }" selected="selected">${rl.repairName }</option>
									</c:when>
									<c:otherwise>
										<option data-val="${rl.repairName }" value="${rl.id }">${rl.repairName }</option>
									</c:otherwise>
								</c:choose>
							</c:forEach>
						</select>
					</li>
                </ul>
                <div class="button_wrap button_wrap2">
                	<a href="javascript:;" onClick="saveSubmit();">保存</a>
                	<c:if test="${type=='save' }">
	                    <a href="javascript:;" onClick="reset();">重置</a>
                	</c:if>
                </div>
            </div>
        </div>
        <!--content-->
        <!--foot-->
        <jsp:include page="../../../common/foot.jsp"/>
        <!--foot-->
    </div>
    <!--main-->
</div>
<!--container-->
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
<script type="text/javascript">

$(function(){
	initSelect();
	
});

function changeType(){
	var type=$("input[name='chType']:checked").val();;
    $("#partnerId").val(0);
    $("#type").val(type);
    if(type == 1){
        $("#partnerIdLi").show();
    }else{
        $("#partnerIdLi").hide();
    }
}


//初始化select
function initSelect(){
	if($("#loginPwd").length>0){
		//新增才做默认初始化
	    //$("#department").find("option[data-val='技术部']").attr("selected",true);
	   // $("#position").find("option[data-val='总监']").attr("selected",true);
	    $("#roleId").find("option[data-val='admin']").attr("selected",true);
	}
}

function loginNameValide(e){
	return regValide(e,/^[A-Za-z0-9]{5,22}$/,"输入有误,由5-22位字母、数字组成！",true);
}

function loginPwdValide(e){
	return regValide(e,/^[A-Za-z0-9]{6,22}$/,"输入有误,由6-22位字母、数字组成！",true);
}

function confirmPwdValide(e){
	var reg = /^[A-Za-z0-9]{6,22}$/;
	var p = createMsg(e);
	if (!reg.test($(e).val())) {
		p.attr("class","zhu_shi_1");
		p.text("输入有误,由6-22位字母、数字组成！");
		return false;
	}
	if ($("#loginPwd").val()!=$(e).val()) {
		p.attr("class","zhu_shi_1");
		p.text("两次输入密码不一致！");
		return false;
	}
	p.attr("class","s_tips");
	p.text("");
	return true;
}

function userNameValide(e){
	return regValide(e,/^[\u4E00-\u9FA5]{2,10}$/,"输入有误,由2-10位汉字组成！",true);
}

function companyValide(e){
	return regValide(e,/^[\u4E00-\u9FA5a-zA-Z]{2,30}$/,"输入有误,由2-30位字母或汉字组成！",true);
}

function phoneValide(e){
	return regValide(e,/^1[3|4|5|8][0-9]\d{8}$/,"输入有误,由11位数字组成！",true);
}

//获取form表单所有参数
function getParams(){
	var json = {};
	$(".content input,.content select").each(function(i,e){
		json[$(e).attr("id")] = $(e).attr("value");
	});
	return json;
}

//重置表单
function reset(){
	$(".inputInfoList3 input").each(function(i,e){
			$(e).val("");
	});
	//重置select
	initSelect();
	//重置提示
	$(".s_tips,.e_tips").each(function(i,e){
		$(e).remove();
	});
}

//保存操作员
function saveSubmit(){
	if ("${sutype}"=="save") {
		if (!loginNameValide($("#loginName"))) {
			return;
		}
		if (!loginPwdValide($("#loginPwd"))) {
			return;
		}
		if (!confirmPwdValide($("#confirmPwd"))) {
			return;
		}
	}
	if (!userNameValide($("#name"))) {
		return;
	}
	if (!companyValide($("#company"))) {
		return;
	}
	if (!phoneValide($("#phone"))) {
		return;
	}
	var chType = $("#type").val();
	
	if (chType == null || chType.length < 1){
		prompt.alert("请选择用户类型");
		return ;
	}
	$.ajax({
		   type: "POST",
		   url: "${pageContext.request.contextPath}/operatorManagement/saveOrUpdateOperator?sutype=${sutype}",
		   dataType:"json",
		   data:getParams(),
		   success: function(data){
		   		if ("登录名已存在!"==data.msg) {
					var i = createTip($("#loginName"));
					i.attr("class","e_tips");
					i.html(data.msg);
					return;
				}
		   		prompt.alert(data.msg,function(){
		   			if (data.errorCode=="0") {
						window.location.href="operatorManagement/showOperatorList";
					}
		   		});
		   }
	});
	
}

</script>
</body>
</html>